package com.mzy.datepackage.M2022.Feb.eightteen;

/**
 * @author Ives
 * * @date 2022/2/18
 */

import java.util.ArrayList;

/**
 * main作为java程序启动的入口，需要了解JVM才能了解全貌
 * main为C++编写
 */
public class demo {
  public static void main(String[] xx) {
    for (int i = 0; i < xx.length; i++) {
      System.out.println(xx[i]);
    }

    ListNode listNode3 = new ListNode(4);
    ListNode listNode2 = new ListNode(2,listNode3);
    ListNode listNode = new ListNode(1,listNode2);

    System.out.println(listNode.val);
    System.out.println(listNode.next.next.val);

  }


  public static class ListNode {
    int val;
    ListNode next;

    ListNode() {
    }

    ListNode(int val) {
      this.val = val;
    }

    ListNode(int val, ListNode next) {
      this.val = val;
      this.next = next;
    }
  }

  public static ListNode mergeTwoLists(ListNode list1, ListNode list2) {
    ListNode dummy = new ListNode(-1), p = dummy;

    while (list1 != null && list2 != null) {
      if (list1.val < list2.val) {
        p.next = list1;
        list1 = list1.next;
      } else {
        p.next = list2;
        list2 = list2.next;
      }
      p = p.next;
    }
    if (list1 != null) p.next = list1;
    if (list2 != null) p.next = list2;
    p.next = (list1 != null ? list1 : list2);
    return dummy.next;
  }
}
